package com.wujin.provider.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wujin.provider.dao.UserDao;
import com.wujin.provider.dubbo.provider.DemoService;
import com.wujin.provider.model.User;
import com.wujin.provider.model.UserBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

/**
 * @author Wu Jin
 * @create 2018-03-28 上午 10:01
 */
@RestController
public class UserController {

    @Autowired
    private UserDao userDao;

    @GetMapping("/list")
    public List<User> list() {
        return userDao.findAll();
    }

    @GetMapping("/list2")
    public PageInfo<UserBean> list2(@RequestParam int num, @RequestParam int size) {
        Page<UserBean> userBeans = PageHelper.startPage(num, size, "id desc");
        userDao.findAll();
        return userBeans.toPageInfo();
    }

    @PostMapping
    public Object insert(@ModelAttribute User user) {
        user.setId(UUID.randomUUID().toString().replace("-", ""));
        return userDao.insert(user);
    }
}
